<?php

function apply_patch($patch)
{
	$config_php = $patch->site_dir.'etc/conf.d/db.php';
	include ($config_php);
	require_once 'UpMysql.php';
	$db = new UpMysql($config);
	if (!$db->init()) {
		$patch->error = $db->error;
		return false;
	}
	$patch->db = $db;
	$status = true
		&& update_db_schema($patch)
		;
	return $status;
}

// 1.2.2
/**
 * update_db_schema обновление схемы DB.
 *
 * @param mixed $patch
 * @access public
 * @return boolean
 */
function update_db_schema ($patch)
{
	require_once 'MysqlImport.php';
	$patch_sql = $patch->patch_dir . 'patch.sql';
	$sql = file_get_contents($patch_sql);

	$prefix = $patch->db->db_prefix;
	$sql = str_replace('{{prefix}}', $prefix, $sql);

	$m = new MysqlImport(array('import_text' => $sql, 'db' => $patch->db));
	$status = $m->process();
	if (!$status) {
		$patch->error = $m->error;
	}
	return $status;
} // end of function update_db_schema

